Open a file for reading

The following example opens a file for reading

C# .NET

public static String DoTest()
{
         string strRet = "";
         string path = @"c:\temp\MyTestOpenRead.txt";

         // Delete the file if it exists.
         if (!File.Exists(path))
         {
                  // Create the file.
                  FileStream fs1 = File.Create(path);
                  Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file to test File.OpenRead method.");
                  // Add some information to the file.
                  fs1.Write(info, 0, info.Length);
                  fs1.Close();

         }

         // Open the stream and read it back.
         FileStream fs2 = File.OpenRead(path);
         byte[] b = new byte[1024];
         UTF8Encoding temp = new UTF8Encoding(true);
         while (fs2.Read(b,0,b.Length) > 0)
         {
                  strRet += (temp.GetString(b) + "\r\n");
         }
         fs2.Close();
         

         return strRet;         
}

 

Blaze++ .NET

static String DoTest()
{
         String strRet = "";
         String path = "c:\\temp\\MyTestOpenRead.txt";

         // Delete the file if it exists.
         if (!File::Exists(path))
         {
                  // Create the file.
                  FileStream fs1 = File::Create(path);
                  byteA info = UTF8Encoding(true).GetBytes("This is some text in the file to test File.OpenRead method.");
                  // Add some information to the file.
                  fs1.Write(info, 0, info.Length);
                  fs1.Close();
         }

         // Open the stream and read it back.
         FileStream fs2 = File::OpenRead(path);
         byteA b(1024);
         UTF8Encoding temp(true);
         while (fs2.Read(b,0,b.Length) > 0)
         {
                  strRet += (temp.GetString(b) + "\r\n");
         }
         fs2.Close();

         return strRet;         
}